package net.ck.hzq;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.alipay.sdk.app.PayTask;
import com.google.gson.Gson;
import com.tencent.mm.opensdk.modelpay.PayReq;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.Map;

import Bean.AliPayBean;
import Bean.AliPayParamBean;
import Bean.JifenParamBean;
import Utils.AuthResult;
import Utils.HelloWordModel;
import Utils.PayResult;
import Utils.StringUtil;
import Utils.SystemDatas;
import base.BaseAct;
import base.BaseBiz;
import coom.Constants;
import coom.MyType;
import event.CloseActEvent;
import event.NetErrorEvent;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Response;
import ui.activity.login.biz.LoginBiz;
import ui.activity.mine.PayPwdAct;
import ui.activity.order.OrderAct;
import ui.activity.profit.biz.WXPayBiz;
import ui.model.AccountMoneyInfo;
import ui.model.BalancePayBean;
import ui.model.IntegralBuyResBean;
import ui.model.IntegralTotalBean;
import ui.model.ItemsInfo;
import ui.model.WxBean;
import util.HtmlTagHandler;
import util.LogUtils;
import util.SysUtils;
import util.ToastUtils;
import widget.alertview.AlertView1;
import widget.alertview.OnItemClickListener;
import widget.dialog.InputPwdDialog;
import widget.dialog.MyDialog;
import widget.dialog.SetPwdDialog;

public class PaymentorderActivity extends BaseAct implements View.OnClickListener {

    //    public static final String APPID = "2018102961919162";
//
//    /**
//     * 用于支付宝账户登录授权业务的入参 pid。
//     */
//    public static final String PID = "2088331272144533";
//
//    /**
//     * 用于支付宝账户登录授权业务的入参 target_id。
//     */
//    public static final String TARGET_ID = "";
//
//    /**
//     * pkcs8 格式的商户私钥。
//     * <p>
//     * 如下私钥，RSA2_PRIVATE 或者 RSA_PRIVATE 只需要填入一个，如果两个都设置了，本 Demo 将优先
//     * 使用 RSA2_PRIVATE。RSA2_PRIVATE 可以保证商户交易在更加安全的环境下进行，建议商户使用
//     * RSA2_PRIVATE。
//     * <p>
//     * 建议使用支付宝提供的公私钥生成工具生成和获取 RSA2_PRIVATE。
//     * 工具地址：https://doc.open.alipay.com/docs/doc.htm?treeId=291&articleId=106097&docType=1
//     */
//    public static final String RSA2_PRIVATE = "\n" +
//            "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDA6Y8tbA7J/7v1\n" +
//            "7friQOYAxBjBi8ryX4TJVHJXLte2YNJCPOR2LftR2unIhLSyi+bjedE1frOzvaBS\n" +
//            "92UPqytTip2X6Q0obmyRz5oQBoF7U++0wIbUIF3NZBM+Z5tlQVeJwCGpJHuwcPB/\n" +
//            "qMsDfOtn8PeUCg/ItGmumkxxuAIagvoAAbygBOEnvFHZmtfamgHO4VEAuwogX8lg\n" +
//            "aWjvJpwsIb9BdpmTfbYICdhKX/vJt5rJW0b/dodEICbgxAIKIANWrmJYaG2tJK6y\n" +
//            "Kw6WtRWqbsmAzoTI48QERVKa+63zrge3oy/cXKXR81RE5IiUYYnwOajqBFegxDFo\n" +
//            "RD4B8AYdAgMBAAECggEANZNn8Sx2ewEsGWPrblSpzAKqAW6qgV+nyCZMzwuyWvNO\n" +
//            "0ZiJtoyUpKoQjWDVslSKXhih0qKKk9uRIBmXFp/qG3x+wga2YckxG9m1Jsg3w6GP\n" +
//            "C/sANv96LaWido1dqeRYxGf4sTnxpBHpqPqezywtUKOqjpGwyoPYaeZuXpLE+slz\n" +
//            "YWJX1/ezkxGEID0MTmeKiE763Z6y4E+ybrSY94qUkD76fUayBWOhoih7+SO7+CEd\n" +
//            "fvavYmJnag2b7+wmoL6lIraFNu/fUEvw9eJr6TBT3w0xIq6iMNdqzAf7W/Bw/C7j\n" +
//            "IQPGmuOWBmxuSUD9MD/KoQZdF0vQXMZY74NCzDyO/QKBgQDzol/cXoBOSwH2zRb7\n" +
//            "XqlRyfi2MVOzT8Xd7rWO37IyVIoxeUH/f5IhAppHiJn6rnAKAu1StSmMoLzbyV37\n" +
//            "NZ2G5D6ZhJmmkNk1R//16m1dE/3a1Y7+lAmX/atLLgGyId3rJ5+X5n3OZ7FKjeZI\n" +
//            "w2O3OIffA/+B/7cv6FvUpNODBwKBgQDKtCMPsX88QI+qSAlRYyxv8L77xFcr2HvW\n" +
//            "gnCN+t6laRpAQ+8hPimt8pnUVMz6pw7U+dlkpErmdl1tpFu8wBjqKg/q2DV6YfhU\n" +
//            "3KAQrOVKzcIvIZ+whZd+f2HgGcF4jgGv1xnHmpW7YhDMxmBnYNmpzflLWFBQHUOq\n" +
//            "yjYaaLIwuwKBgFe6vYgN42fN7KwhV8g2YwQXlV6NzpUAAcETxv7moDUtagG8pz5I\n" +
//            "gqcuV72we7nf/GoueaTRpV+FNdxy20utF8dOAximvelTuVNNVOcJfk4I991ID1Cu\n" +
//            "n/HCH19X9rZdKZsWzooVLnIXtqihBi5nZU3BpnNw7h2yphUzN3YP0DYbAoGBAIke\n" +
//            "1DzweD6c+dJZypvYt529wKP1THanihYwxMz2sJg6gfyJOAFH2NAHtZHSD5tbWQgv\n" +
//            "P6T6EoTV+xuJPFlxpSj6bSwTOBHipidZ25mMK8uvZrWVTD4QEMwMhXwgUCUqAvAd\n" +
//            "VR4Wb0WD8BNl+p7UAEoCwKn8Qs//C+BDy9ePjUKzAoGBAKHVBN1z5yueqqpPq42R\n" +
//            "xyw9mLuES0J8TEZv4QODPRhYfQjQSzXHugogXnqErphUFX8fLkN7nihb3pzuvd0+\n" +
//            "jrxjAqXQ46ax+FErhySsq/UgcKHlyQeM+4Z8gEl1pbaW/xzx3ZFl8EHZ5O/K1iio\n" +
//            "/XkQOdas1JXoXQIIJ1ixAszX";
//
//    public static final String RSA_PRIVATE = "";
//
    private static final int SDK_PAY_FLAG = 1;
    private static final int SDK_AUTH_FLAG = 2;

    private ImageView paymentorder_back;

    private TextView paymentorder_txt_price,jifenzhifu;

    private TextView yu;

    private Button but_confimpay;

    private String payId;

    private ImageView paymentorder_cb1, paymentorder_cb2, paymentorder_cb3,paymentorder_jf;

    //微信支付
    private WXPayBiz wxPayBiz;

    private IWXAPI api;

    // 0 余额支付1 支付宝 2微信 3积分
    private int payType = 1;

    private InputMethodManager imm;
    EditText etName;//拓展View内容
    //拓展窗口
    AlertView1 mAlertViewExt;

    private SharedPreferences sp;
    String phoneNumber;

    double balanceMoney = 0;
    double goodsPrice = 0;
    private int pay  = 0;

    private SetPwdDialog setPwdDialog;
    private InputPwdDialog inputPwdDialog;


    private Handler mHandler = new Handler() {
        @SuppressWarnings("unused")
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case SDK_PAY_FLAG: {
                    @SuppressWarnings("unchecked")
                    PayResult payResult = new PayResult((Map<String, String>) msg.obj);
                    String resultInfo = payResult.getResult();// 同步返回需要验证的信息
                    String resultStatus = payResult.getResultStatus();
                    if (TextUtils.equals(resultStatus, "9000")) {
//                        setResult(Activity.RESULT_OK);
//                        finish();
                        pay =1;
                        jumpToOrder();
                        Toast.makeText(getApplicationContext(), "支付成功", Toast.LENGTH_SHORT).show();
                    } else if (TextUtils.equals(resultStatus, "6001")) {
                        Toast.makeText(PaymentorderActivity.this, "支付取消", Toast.LENGTH_SHORT).show();
                        pay = 0;
                        jumpToOrder();
                    } else {
                        Toast.makeText(PaymentorderActivity.this, "支付失败: " + payResult, Toast.LENGTH_SHORT).show();
                        pay = 0;
                        jumpToOrder();
                    }
                    break;
                }
                case SDK_AUTH_FLAG: {
                    @SuppressWarnings("unchecked")
                    AuthResult authResult = new AuthResult((Map<String, String>) msg.obj, true);
                    String resultStatus = authResult.getResultStatus();
                    if (TextUtils.equals(resultStatus, "9000") && TextUtils.equals(authResult.getResultCode(), "200")) {
                        Toast.makeText(PaymentorderActivity.this, "授权成功: " + authResult, Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(PaymentorderActivity.this, "授权失败: " + authResult, Toast.LENGTH_SHORT).show();
                    }
                    break;
                }
                default:
                    break;
            }
        }
    };

    @Override
    protected void setRoot() {
        setContentView(R.layout.activity_paymentorder);
    }

    @Override
    protected void init(@Nullable Bundle savedInstanceState) {
        sp = getSharedPreferences("ToBuy", Context.MODE_PRIVATE);
        phoneNumber = sp.getString("phonenumber", "");
        imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        Constants.activitys.add(this);
        wxPayBiz = new WXPayBiz();
        api = WXAPIFactory.createWXAPI(this, Constants.APP_ID, true);
        api.registerApp(Constants.APP_ID);
        TobuyApplication.getmInstance().onActivityCreate(this);
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
        paymentorder_cb1 = findViewById(R.id.paymentorder_cb1);
        paymentorder_cb2 = findViewById(R.id.paymentorder_cb2);
        paymentorder_cb3 = findViewById(R.id.paymentorder_cb3);
        paymentorder_jf = findViewById(R.id.paymentorder_jf);
        jifenzhifu = findViewById(R.id.jifenzhifu);
        paymentorder_txt_price = findViewById(R.id.paymentorder_txt_price);
        paymentorder_back = findViewById(R.id.paymentorder_back);
        but_confimpay = findViewById(R.id.but_confimpay);
        yu = findViewById(R.id.yue_money);
        if (getIntent().getStringExtra("price") != null) {
            paymentorder_txt_price.setText("¥ " + getIntent().getStringExtra("price"));
            payId = getIntent().getStringExtra("id");
            try {
                goodsPrice = Double.valueOf(getIntent().getStringExtra("price"));
            } catch (Exception e) {

            }
        }
        paymentorder_back.setOnClickListener(this);
        but_confimpay.setOnClickListener(this);
        findViewById(R.id.ali_layout).setOnClickListener(this);
        findViewById(R.id.wx_layout).setOnClickListener(this);
        findViewById(R.id.yue_layout).setOnClickListener(this);
        findViewById(R.id.jf_layout).setOnClickListener(this);
        getUserMoney();
        getData();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.paymentorder_back:
                setResult(Activity.RESULT_CANCELED);
                finish();
                break;
            case R.id.ali_layout:
                payType = 1;
                paymentorder_cb1.setBackgroundResource(R.mipmap.ic_pay_true);
                paymentorder_cb2.setBackgroundResource(R.mipmap.ic_pay_false);
                paymentorder_cb3.setBackgroundResource(R.mipmap.ic_pay_false);
                paymentorder_jf.setBackgroundResource(R.mipmap.ic_pay_false);
                break;
            case R.id.wx_layout:
                payType = 2;
                paymentorder_cb1.setBackgroundResource(R.mipmap.ic_pay_false);
                paymentorder_cb2.setBackgroundResource(R.mipmap.ic_pay_true);
                paymentorder_cb3.setBackgroundResource(R.mipmap.ic_pay_false);
                paymentorder_jf.setBackgroundResource(R.mipmap.ic_pay_false);
                break;
            case R.id.yue_layout:
                payType = 0;
                paymentorder_cb1.setBackgroundResource(R.mipmap.ic_pay_false);
                paymentorder_cb2.setBackgroundResource(R.mipmap.ic_pay_false);
                paymentorder_cb3.setBackgroundResource(R.mipmap.ic_pay_true);
                paymentorder_jf.setBackgroundResource(R.mipmap.ic_pay_false);
                break;
            case R.id.jf_layout:
                payType = 3;
                paymentorder_cb1.setBackgroundResource(R.mipmap.ic_pay_false);
                paymentorder_cb2.setBackgroundResource(R.mipmap.ic_pay_false);
                paymentorder_cb3.setBackgroundResource(R.mipmap.ic_pay_false);
                paymentorder_jf.setBackgroundResource(R.mipmap.ic_pay_true);
                break;
            case R.id.but_confimpay:
                //TODO
                if (payType == 1) {
                    AliPayParamBean a = new AliPayParamBean();
                    a.setId(Integer.parseInt(payId));
                    Call<AliPayBean> userMsgCall = HelloWordModel.getInstance(PaymentorderActivity.this).AliPay(SystemDatas.GetService_URL("alipay"), a);//, sp.getString("token", null)
                    userMsgCall.enqueue(new retrofit2.Callback<AliPayBean>() {
                        @Override
                        public void onResponse(Call<AliPayBean> call, final Response<AliPayBean> response) {

                            if (response.body().getMsg().equals("success")) {
                                try {
                                    final String orderInfo = response.body().getData().getSign();

                                    Runnable payRunnable = new Runnable() {

                                        @Override
                                        public void run() {
                                            PayTask alipay = new PayTask(PaymentorderActivity.this);
                                            Map<String, String> result = alipay.payV2(orderInfo, true);
                                            Log.i("msp", result.toString());
                                            Message msg = new Message();
                                            msg.what = SDK_PAY_FLAG;
                                            msg.obj = result;
                                            mHandler.sendMessage(msg);
                                        }
                                    };
                                    Thread payThread = new Thread(payRunnable);
                                    payThread.start();
                                } catch (Exception e) {

                                }
                            } else {
                                Toast.makeText(PaymentorderActivity.this, response.body().getMsg(), Toast.LENGTH_SHORT).show();
                            }

                        }

                        @Override
                        public void onFailure(Call<AliPayBean> call, Throwable t) {

                        }
                    });
                } else if (payType == 2) {
                    WxPay(payId);
                } else if (payType == 0) {
                    if (goodsPrice > balanceMoney) {
                        ToastUtils.shortToast("您的余额不足");
                        return;
                    }
                    getPwdInfo();
                }
                else if(payType == 3){
                    jifenPay(payId);
                }
                break;
        }
    }
    private void getData(){
        new LoginBiz().integralTotal(TobuyApplication.customId, new BaseBiz.Callback<IntegralTotalBean>() {
            @Override
            public void onSuccess(IntegralTotalBean integralTotalBean) {

                String str = "积分支付<myfont color=#999999 size='25px' >（当前可用积分:" + integralTotalBean.getIntegral() + ")</myfont>";
                Spanned str1 = Html.fromHtml(str, null, new HtmlTagHandler("myfont"));
                jifenzhifu.setText(str1);
            }

            @Override
            public void onFailure(IntegralTotalBean integralTotalBean) {

            }
        });


    }

    private void jifenPay(String id) {
            JifenParamBean a = new JifenParamBean();
            a.setOrderId(Integer.parseInt(id));
            RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new Gson().toJson(a));
            wxPayBiz.JFPay(requestBody, new BaseBiz.Callback<IntegralBuyResBean>() {
                @Override
                public void onSuccess(IntegralBuyResBean wxBean) {
                   if(wxBean.getFlag()){
                       ToastUtils.shortToast("支付成功！");
                       finishAct();
                   }else{
                       ToastUtils.shortToast(wxBean.getMsg());
                   }
                }

                @Override
                public void onFailure(IntegralBuyResBean o) {
                    LogUtils.d("2err:" + o);
                }
            });
    }

    private void WxPay(String id) {
        if (SysUtils.isWeixinAvilible(PaymentorderActivity.this)) {
            AliPayParamBean a = new AliPayParamBean();
            a.setId(Integer.parseInt(id));
            RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new Gson().toJson(a));
            wxPayBiz.WXPay(requestBody, new BaseBiz.Callback<WxBean>() {
                @Override
                public void onSuccess(WxBean wxBean) {
                    PayReq req = new PayReq();
                    req.appId = wxBean.getAppid();
                    req.partnerId = wxBean.getPartnerid();
                    req.prepayId = wxBean.getPrepayid();
                    req.packageValue = "Sign=WXPay";
                    req.nonceStr = wxBean.getNoncestr();
                    req.timeStamp = wxBean.getTimestamp();
                    req.sign = wxBean.getSign();
                    req.extData = "app data";
                    api.sendReq(req);
                }

                @Override
                public void onFailure(WxBean o) {
                    LogUtils.d("2err:" + o);
                }
            });
        } else {
            ToastUtils.shortToast("您还未安装微信");
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onCloseActEvent(CloseActEvent event) {
        if (event.getType() == MyType.WXPay) {
            jumpToOrder();
        }
    }

    private void jumpToOrder() {
        Intent intent = new Intent(PaymentorderActivity.this, OrderAct.class);
        intent.putExtra("pay",pay);
        startActivity(intent);
        if (Constants.activitys.size() > 0) {
            for (Activity act :
                    Constants.activitys) {
                act.finish();
            }
            Constants.activitys.clear();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
        wxPayBiz.onDestory();
    }

    @Override
    protected void onNetError(NetErrorEvent event) {

    }

    /**
     * 获取用户余额
     */
    private void getUserMoney() {
        wxPayBiz.getUserIncome(new BaseBiz.Callback<ItemsInfo<AccountMoneyInfo>>() {
            @Override
            public void onSuccess(ItemsInfo<AccountMoneyInfo> info) {
                try {
                    balanceMoney = Double.valueOf(info.getItems().getDividedTotal()) + Double.valueOf(info.getItems().getReturnTotal())+Double.valueOf(info.getItems().getRecommendAmount());
                    String str = "余额支付<myfont color=#999999 size='25px' >（当前可用余额¥" + String.format("%.2f", balanceMoney) + ")</myfont>";
                    Spanned str1 = Html.fromHtml(str, null, new HtmlTagHandler("myfont"));
                    yu.setText(str1);
                } catch (Exception e) {

                }


            }

            @Override
            public void onFailure(ItemsInfo<AccountMoneyInfo> info) {
            }
        });
    }

    /**
     * 获取验证码
     */
    private void getCode() {
        showEdit();
        wxPayBiz.yuPay(new BaseBiz.Callback<Object>() {
            @Override
            public void onSuccess(Object info) {

            }

            @Override
            public void onFailure(Object info) {
            }
        });
    }


    /**
     * 余额支付
     */
    private void balancePay(String code) {
        loading(true);
        BalancePayBean balancePayBean = new BalancePayBean();
        balancePayBean.setOrderId(payId);
        balancePayBean.setSecret(code);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new Gson().toJson(balancePayBean));
        wxPayBiz.balancePay(requestBody, new BaseBiz.Callback<Object>() {
            @Override
            public void onSuccess(Object info) {
                ToastUtils.shortToast("支付成功");
                loading(false);
                if (inputPwdDialog != null && inputPwdDialog.isShowing()) {
                    inputPwdDialog.dismiss();
                }
                pay =1;
                jumpToOrder();

            }

            @Override
            public void onFailure(Object info) {
//                ToastUtils.shortToast("支付失败");
                if (inputPwdDialog != null && inputPwdDialog.isShowing()) {
                    inputPwdDialog.setClearText();
//                    inputPwdDialog.dismiss();
                    inputPwdDialog.setSubmitEnable(true);
                }

                pay = 0;
                loading(false);
            }
        });
    }

    /**
     * 弹出验证码输入框
     */

    private void showEdit() {
        if (mAlertViewExt == null) {
            String phone = "";
            if (phoneNumber.length() > 4) {
                phone = phoneNumber.substring(phoneNumber.length() - 4, phoneNumber.length());
            } else {
                phone = "登录手机号";
            }
            //拓展窗口
            mAlertViewExt = new AlertView1("短信验证码", "已向您的尾号" + phone + "的手机发送验证码", "取消",
                    null, new String[]{"确定"}, this, AlertView1.Style.Alert, new OnItemClickListener() {
                @Override
                public void onItemClick(Object o, int position) {
                    closeKeyboard();
                    if (position == 0) {
                        if (StringUtil.isNullOrEmpty(etName.getText().toString().trim())) {
                            ToastUtils.shortToast("请输入验证码");
                            return;
                        }
                        balancePay(etName.getText().toString().trim());
                    }
                    mAlertViewExt.dismiss();
                }
            });
            ViewGroup extView = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.alertext_form, null);
            etName = extView.findViewById(R.id.etName);
            etName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View view, boolean focus) {
                    //输入框出来则往上移动
                    boolean isOpen = imm.isActive();
                    mAlertViewExt.setMarginBottom(isOpen && focus ? 120 : 0);
                }
            });
            mAlertViewExt.addExtView(extView);
        }
        mAlertViewExt.show();
    }

    private void closeKeyboard() {
        //关闭软键盘
        imm.hideSoftInputFromWindow(etName.getWindowToken(), 0);
        //恢复位置
        mAlertViewExt.setMarginBottom(0);
    }

    /**
     * 屏蔽验证码输入框
     *
     * @param keyCode
     * @param event
     * @return
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            if (mAlertViewExt != null && mAlertViewExt.isShowing()) {
                mAlertViewExt.dismiss();
                return false;
            }
        }
        return super.onKeyDown(keyCode, event);
    }


    /**
     * 设置提现验证码
     */


    public void showAddPwd() {
        if (setPwdDialog == null) {
            setPwdDialog = new SetPwdDialog(this, "", new MyDialog.DialogCallback() {
                @Override
                public void OnConfirm() {
                    toAddPwd();
                    if (setPwdDialog != null && setPwdDialog.isShowing()) {
                        setPwdDialog.dismiss();
                    }
                }

                @Override
                public void OnConfirm1() {

                }

                @Override
                public void OnCancel() {

                }
            });
        }
        setPwdDialog.show();
    }

    public void showPwd() {
        if (inputPwdDialog == null) {
            inputPwdDialog = new InputPwdDialog(this, new MyDialog.DialogCallback() {
                @Override
                public void OnConfirm() {
                    if (StringUtil.isNullOrEmpty(inputPwdDialog.getEditNumber()) || inputPwdDialog.getEditNumber().length() != 6) {
                        ToastUtils.shortToast("请输入完整的提现密码");
                        return;
                    }
                    balancePay(inputPwdDialog.getEditNumber());
                }

                @Override
                public void OnConfirm1() {
                    toAddPwd();
//                    if (inputPwdDialog != null && inputPwdDialog.isShowing()) {
//                        inputPwdDialog.dismiss();
//                    }
                }

                @Override
                public void OnCancel() {

                }
            });
        }
        inputPwdDialog.show();
        inputPwdDialog.setClearText();
    }

    public void toAddPwd() {
        Intent intent = new Intent(PaymentorderActivity.this, PayPwdAct.class);
        startActivity(intent);
    }

    public void getPwdInfo() {
        loading(true);
        wxPayBiz.getPwd(new BaseBiz.Callback<Boolean>() {
            @Override
            public void onSuccess(Boolean info) {
                if (info) {
                    showPwd();
                } else {
                    showAddPwd();
                }
                loading(false);

            }

            @Override
            public void onFailure(Boolean info) {
                loading(false);
            }
        });
    }

}
